package mo.tags.stack;

import java.util.Stack;

public class L1006 {

    public int clumsy(int n) {
        Stack<Integer> stack = new Stack<>();
        stack.push(n);
        n--;
        int idx = 0;
        while (n > 0) {
            if (idx % 4 == 0) {
                stack.push(stack.pop()*n);
            } else if (idx % 4 == 1) {
                stack.push(stack.pop() / n);
            } else if (idx % 4 == 2) {
                stack.push(n);
            } else {
                stack.push(-n);
            }
            n--;
            idx++;
        }
        int sum = 0;
        while (!stack.isEmpty()) {
            sum += stack.pop();
        }
        return sum;
    }

}
